//
//  GLMutiVideoPlayerView.swift
//  BigData
//
//  Created by quan on 2019/10/16.
//  Copyright © 2019 scglxx. All rights reserved.
//

import UIKit

/**
 *  也是单一的播放器，只是特定了样式，用于多视频播放
 */
class GLMutiVideoPlayerView: GLVideoPlayerView {
    
    var isFullScreen = false {
        didSet {
            DispatchQueue.main.async {
                self.titleLabel.isHidden = self.isFullScreen
                if self.isFullScreen {
                    self.gestureActionView.bottomBGView.snp.remakeConstraints { (make) in
                        make.left.right.bottom.equalToSuperview()
                        make.height.equalTo(44)
                    }
                }
                else {
                    self.gestureActionView.bottomBGView.snp.remakeConstraints { (make) in
                        make.left.right.bottom.equalToSuperview()
                        make.height.equalTo(28)
                    }
                }
            }
        }
    }
    var title: String? {
        didSet {
            DispatchQueue.main.async {
                self.titleLabel.text = self.title
            }
        }
    }
    private var titleLabel = UILabel.init()
    private var bottomView = GLGradualView.init(type: .fromBottomToTop)
    
    init(type: GLVideoPlayerType, urlString: String, title: String? = nil) {
        self.title = title
        super.init(type: type, urlString: urlString, needCheckNeetwork: false)
        self.backgroundColor = .black
        self.gestureActionView.titleLabel.isHidden = true
        self.gestureActionView.topBGView.isHidden = true
        self.gestureActionView.bottomBGView.snp.removeConstraints()
        self.gestureActionView.bottomBGView.gradientLayer.removeFromSuperlayer()
        self.gestureActionView.addSubview(bottomView)
        self.bottomView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(56)
        }
        
        self.bottomView.addSubview(self.gestureActionView.bottomBGView)
        self.gestureActionView.bottomBGView.snp.remakeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(28)
        }
        
        titleLabel.text = title
        titleLabel.font = .systemFont(ofSize: 12, weight: .medium)
        titleLabel.textColor = .white
        self.bottomView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.top.equalToSuperview()
            make.height.equalTo(28)
        }
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setTitleLabelShow(_ show: Bool) {
       UIView.animate(withDuration: 0.25) {
        self.titleLabel.alpha = show ? 1.0 : 0.0
        }
    }
}
